<?php


namespace App\Models\Logs;

use App\Models\System\User;
use App\Traits\DateTrait;
use Illuminate\Database\Eloquent\Model;

class ActivityLog extends \Spatie\Activitylog\Models\Activity
{
    use DateTrait;

    public function user()
    {
        return $this->hasOne(User::class, 'id', 'causer_id');
    }

    /**
     * @param string|null $desc
     * @param array|Model $properties
     * @param string $inLog
     */
    public static function createSyslog(?string $desc, $properties, string $inLog = 'Syslog'): void
    {
        try {
            $activity = activity()->inLog($inLog)->causedBy(auth('admin')->user());
            if (!empty($properties) && $properties instanceof Model) {
                $activity->performedOn($properties);
            }
            $activity->withProperties($properties)->log($desc);
        }catch (\Exception $e) {
            report($e);
        }
    }
}
